FUNCTION_BLOCK LCB_Norm_nToSpeed_s 
TITLE = 'LCB_Norm_nToSpeed_s'

// This FB uses the transmitted machine parameters and converts a scaled 32-bit signal into a 32-bit speed signal.
//
// Versionshistory:
// 1.0 Ersterstellung R.Enders 

VERSION : '1.0'
AUTHOR  : 'Lenze'
FAMILY  : 'LCB'
NAME : 'NnToSs' // ( 8 Zeichen max.)
KNOW_HOW_PROTECT


VAR_INPUT
    diIn_n        : DINT;
    AxisData      : BLOCK_DB; AxisData DB-Nr
    
END_VAR

VAR_OUTPUT
    diOut_s       : DINT;
    xError        : BOOL;
END_VAR

VAR
   rOut_s               : REAL;
   dwReferenceSpeed     : dword; 
   rReferenceSpeed      : REAL;
      
END_VAR


BEGIN
dwReferenceSpeed:= AxisData.dd16 ;  // BLOCK_DB Zugriffe nur mit Word bzw. DWORD erlaubt
rReferenceSpeed:= DWORD_TO_REAL (dwReferenceSpeed);

(* Berechnung Geschwindigkeit *)
     rOut_s := (  DINT_TO_REAL(diIn_n) *  rReferenceSpeed /  1073741824.0);
      
(*Limitierung auf 32Bit Zahlenbereich *)
      rOut_s := LIMIT(MN:= -2147483568.0,IN:=rOut_s,MX:=2147483568.0);
      diOut_s := REAL_TO_DINT(rOut_s);
      
      IF rReferenceSpeed <= 0 THEN   xError := True;
      ELSE xError := False;
      END_IF;
END_FUNCTION_BLOCK




    
